// var i;
// var AL_GAME_HUA_AddPrefab = require("./AL_GAME_HUA_AddPrefab");
// var AL_GAME_HUA_Instance = require("./AL_GAME_HUA_Instance");
// var AL_GAME_HUA_Common = require("./AL_GAME_HUA_Common");
// var AL_GAME_HUA_Define = require("./AL_GAME_HUA_Define");
// var AL_GAME_HUA_PopupSelf = require("./AL_GAME_HUA_PopupSelf");
// var AL_GAME_HUA_GameConst = require("./AL_GAME_HUA_GameConst");
// var AL_GAME_HUA_CurrencyData = require("./AL_GAME_HUA_CurrencyData");
// var AL_GAME_HUA_EventConfig = require("./AL_GAME_HUA_EventConfig");
// var AL_GAME_HUA_GoodsConfig = require("./AL_GAME_HUA_GoodsConfig");
// var P = cc._decorator;
// var g = P.ccclass;
// var y = P.property;
// var m =
//     (P.menu,
//     (function (e) {
//         function t() {
//             var t = (null !== e && e.apply(this, arguments)) || this;
//             t.video_vit_label = null;
//             return t;
//         }
//         __extends(t, e);
//         t.prototype.start = function () {
//             AL_GAME_HUA_Instance.Instance.xianshi_dingbu_tiao({
//                 target: this.node,
//                 showVit: !0,
//                 showGold: !0,
//                 vitButtonEnable: !1
//             });
//             this.label_button_price.string = AL_GAME_HUA_GameConst.GameConst.getInstance().vit_price.toString();
//             this.video_vit_label.string = "+" + AL_GAME_HUA_GameConst.GameConst.getInstance().video_vit_count;
//         };
//         t.prototype.zhixing_chushihua_chuli = function (e) {
//             this.options = e;
//         };
//         t.prototype.onEnable = function () {
//             AL_APP_SDK_MANAGER.emit(AL_GAME_HUA_Define.GameEvent.ON_GAME_CLUB_HIDE, {
//                 node: this.node,
//                 hide: !0
//             });
//         };
//         t.prototype.onDisable = function () {
//             AL_APP_SDK_MANAGER.emit(AL_GAME_HUA_Define.GameEvent.ON_GAME_CLUB_HIDE, {
//                 node: this.node,
//                 hide: !1
//             });
//         };
//         t.prototype.handle_button_callback = function (e, t) {
//             var n = this;
//             switch (t) {
//                 case "close":
//                     this.close();
//                     if (this.options.onClose) {
//                         this.options.onClose();
//                     }
//                     break;
//                 case "video":
//                     AL_GAME_HUA_Common.Common.showVideo({
//                         success: function (e) {
//                             AL_GAME_HUA_CurrencyData.CurrencyData.getInstance().tianjia_huobi({
//                                 type: AL_GAME_HUA_CurrencyData.CurrencyType.VIT,
//                                 num: AL_GAME_HUA_GameConst.GameConst.getInstance().video_vit_count
//                             });
//                             AL_GAME_HUA_EventConfig.EventConfig.getInstance().assetsReportOutput({
//                                 source: AL_GAME_HUA_EventConfig.AssetsSource.game,
//                                 action:
//                                     2 == e.type
//                                         ? AL_GAME_HUA_EventConfig.AssetsAction.video_get
//                                         : AL_GAME_HUA_EventConfig.AssetsAction.share_get,
//                                 goodsList: [
//                                     {
//                                         goods: AL_GAME_HUA_GoodsConfig.GoodsId.vit,
//                                         num: AL_GAME_HUA_GameConst.GameConst.getInstance().video_vit_count
//                                     }
//                                 ]
//                             });
//                             if (n.options.onBuy) {
//                                 n.options.onBuy();
//                             }
//                         }
//                     });
//                     break;
//                 case "coin":
//                     AL_GAME_HUA_CurrencyData.CurrencyData.getInstance().shiyong_huobi({
//                         type: AL_GAME_HUA_CurrencyData.CurrencyType.COIN,
//                         num: AL_GAME_HUA_GameConst.GameConst.getInstance().vit_price
//                     }).result
//                         ? (AL_GAME_HUA_CurrencyData.CurrencyData.getInstance().tianjia_huobi({
//                               type: AL_GAME_HUA_CurrencyData.CurrencyType.VIT,
//                               num: 1
//                           }),
//                           AL_GAME_HUA_EventConfig.EventConfig.getInstance().assetsReportOutput({
//                               source: AL_GAME_HUA_EventConfig.AssetsSource.game,
//                               action: AL_GAME_HUA_EventConfig.AssetsAction.coin_get,
//                               goodsList: [
//                                   {
//                                       goods: AL_GAME_HUA_GoodsConfig.GoodsId.vit,
//                                       num: 1
//                                   }
//                               ]
//                           }),
//                           this.options.onBuy && this.options.onBuy())
//                         : AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_tishi_jiedian_mianban({
//                               str: "金币不足"
//                           });
//             }
//         };
//         __decorate([y(cc.Label)], t.prototype, "label_button_price", void 0);
//         __decorate([y(cc.Label)], t.prototype, "video_vit_label", void 0);
//         return __decorate([g], t);
//     })(AL_GAME_HUA_PopupSelf.default));
// exports.default = m;


// /**
//  * 这个类是一个弹出窗口的控制器，负责处理相关事件和UI交互。
//  */
// var AL_GAME_HUA_AddPrefab = require("./AL_GAME_HUA_AddPrefab");
// var AL_GAME_HUA_Instance = require("./AL_GAME_HUA_Instance");
// var AL_GAME_HUA_Common = require("./AL_GAME_HUA_Common");
// var AL_GAME_HUA_Define = require("./AL_GAME_HUA_Define");
// var AL_GAME_HUA_PopupSelf = require("./AL_GAME_HUA_PopupSelf");
// var AL_GAME_HUA_GameConst = require("./AL_GAME_HUA_GameConst");
// var AL_GAME_HUA_CurrencyData = require("./AL_GAME_HUA_CurrencyData");
// var AL_GAME_HUA_EventConfig = require("./AL_GAME_HUA_EventConfig");
// var AL_GAME_HUA_GoodsConfig = require("./AL_GAME_HUA_GoodsConfig");

// var { ccclass, property } = cc._decorator;

// var AL_GAME_HUA_Controller = (function (_super) {
//     function Controller() {
//         var self = (_super !== null && _super.apply(this, arguments)) || this;
//         self.video_vit_label = null;
//         self.label_button_price = null;
//         return self;
//     }

//     __extends(Controller, _super);

//     /**
//      * 启动时调用的方法，显示顶部条等信息。
//      */
//     Controller.prototype.start = function () {
//         AL_GAME_HUA_Instance.Instance.xianshi_dingbu_tiao({
//             target: this.node,
//             showVit: true,
//             showGold: true,
//             vitButtonEnable: false
//         });

//         this.label_button_price.string = AL_GAME_HUA_GameConst.GameConst.getInstance().vit_price.toString();
//         this.video_vit_label.string = "+" + AL_GAME_HUA_GameConst.GameConst.getInstance().video_vit_count;
//     };

//     /**
//      * 初始化时调用的方法
//      * @param options 初始化选项
//      */
//     Controller.prototype.zhixing_chushihua_chuli = function (options) {
//         this.options = options;
//     };

//     /**
//      * 启用时调用的方法，发送游戏俱乐部隐藏事件
//      */
//     Controller.prototype.onEnable = function () {
//         AL_APP_SDK_MANAGER.emit(AL_GAME_HUA_Define.GameEvent.ON_GAME_CLUB_HIDE, {
//             node: this.node,
//             hide: true
//         });
//     };

//     /**
//      * 禁用时调用的方法，发送游戏俱乐部显示事件
//      */
//     Controller.prototype.onDisable = function () {
//         AL_APP_SDK_MANAGER.emit(AL_GAME_HUA_Define.GameEvent.ON_GAME_CLUB_HIDE, {
//             node: this.node,
//             hide: false
//         });
//     };

//     /**
//      * 按钮回调处理函数
//      * @param {Object} event 点击事件对象
//      * @param {string} type 按钮类型
//      */
//     Controller.prototype.handle_button_callback = function (event, type) {
//         switch (type) {
//             case "close":
//                 this.close();
//                 if (this.options.onClose) {
//                     this.options.onClose();
//                 }
//                 break;
//             case "video":
//                 AL_GAME_HUA_Common.Common.showVideo({
//                     success: (videoResult) => {
//                         AL_GAME_HUA_CurrencyData.CurrencyData.getInstance().tianjia_huobi({
//                             type: AL_GAME_HUA_CurrencyData.CurrencyType.VIT,
//                             num: AL_GAME_HUA_GameConst.GameConst.getInstance().video_vit_count
//                         });
//                         AL_GAME_HUA_EventConfig.EventConfig.getInstance().assetsReportOutput({
//                             source: AL_GAME_HUA_EventConfig.AssetsSource.game,
//                             action:
//                                 videoResult.type === 2
//                                     ? AL_GAME_HUA_EventConfig.AssetsAction.video_get
//                                     : AL_GAME_HUA_EventConfig.AssetsAction.share_get,
//                             goodsList: [
//                                 {
//                                     goods: AL_GAME_HUA_GoodsConfig.GoodsId.vit,
//                                     num: AL_GAME_HUA_GameConst.GameConst.getInstance().video_vit_count
//                                 }
//                             ]
//                         });
//                         if (this.options.onBuy) {
//                             this.options.onBuy();
//                         }
//                     }
//                 });
//                 break;
//             case "coin":
//                 var currencyResult = AL_GAME_HUA_CurrencyData.CurrencyData.getInstance().shiyong_huobi({
//                     type: AL_GAME_HUA_CurrencyData.CurrencyType.COIN,
//                     num: AL_GAME_HUA_GameConst.GameConst.getInstance().vit_price
//                 }).result;
//                 if (currencyResult) {
//                     AL_GAME_HUA_CurrencyData.CurrencyData.getInstance().tianjia_huobi({
//                         type: AL_GAME_HUA_CurrencyData.CurrencyType.VIT,
//                         num: 1
//                     });
//                     AL_GAME_HUA_EventConfig.EventConfig.getInstance().assetsReportOutput({
//                         source: AL_GAME_HUA_EventConfig.AssetsSource.game,
//                         action: AL_GAME_HUA_EventConfig.AssetsAction.coin_get,
//                         goodsList: [
//                             {
//                                 goods: AL_GAME_HUA_GoodsConfig.GoodsId.vit,
//                                 num: 1
//                             }
//                         ]
//                     });
//                     if (this.options.onBuy) {
//                         this.options.onBuy();
//                     }
//                 } else {
//                     AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_tishi_jiedian_mianban({
//                         str: "金币不足"
//                     });
//                 }
//                 break;
//         }
//     };

//     __decorate([property(cc.Label)], Controller.prototype, "label_button_price", void 0);
//     __decorate([property(cc.Label)], Controller.prototype, "video_vit_label", void 0);

//     return __decorate([ccclass], Controller);
// })(AL_GAME_HUA_PopupSelf.default);

// exports.default = AL_GAME_HUA_Controller;


// 引入所需模块
const AL_GAME_HUA_AddPrefab = require("./AL_GAME_HUA_AddPrefab");
const AL_GAME_HUA_Instance = require("./AL_GAME_HUA_Instance");
const AL_GAME_HUA_Common = require("./AL_GAME_HUA_Common");
const AL_GAME_HUA_Define = require("./AL_GAME_HUA_Define");
const AL_GAME_HUA_PopupSelf = require("./AL_GAME_HUA_PopupSelf");
const AL_GAME_HUA_GameConst = require("./AL_GAME_HUA_GameConst");
const AL_GAME_HUA_CurrencyData = require("./AL_GAME_HUA_CurrencyData");
const AL_GAME_HUA_EventConfig = require("./AL_GAME_HUA_EventConfig");
const AL_GAME_HUA_GoodsConfig = require("./AL_GAME_HUA_GoodsConfig");

const { ccclass, property } = cc._decorator;

/**
 * AL_GAME_HUA_Controller
 * 负责弹出窗口的控制逻辑，包括按钮交互、视频播放奖励以及货币消费逻辑等。
 */
@ccclass
class AL_GAME_HUA_Controller extends AL_GAME_HUA_PopupSelf.default {
    @property(cc.Label)
    label_button_price = null;

    @property(cc.Label)
    video_vit_label = null;

    /**
     * 启动时调用的方法
     * 初始化显示顶部条，并设置价格标签和视频奖励标签内容。
     */
    start() {
        AL_GAME_HUA_Instance.Instance.xianshi_dingbu_tiao({
            target: this.node,
            showVit: true, // 显示体力条
            showGold: true, // 显示金币
            vitButtonEnable: false, // 禁用体力按钮
        });

        // 设置价格和视频奖励标签
        this.label_button_price.string = AL_GAME_HUA_GameConst.GameConst.getInstance().vit_price.toString();
        this.video_vit_label.string = `+${AL_GAME_HUA_GameConst.GameConst.getInstance().video_vit_count}`;
    }

    /**
     * 初始化时调用的方法
     * @param {Object} options 初始化参数
     */
    zhixing_chushihua_chuli(options) {
        this.options = options;
    }

    /**
     * 界面启用时调用的方法
     * 隐藏游戏俱乐部。
     */
    onEnable() {
        AL_APP_SDK_MANAGER.emit(AL_GAME_HUA_Define.GameEvent.ON_GAME_CLUB_HIDE, {
            node: this.node,
            hide: true,
        });
    }

    /**
     * 界面禁用时调用的方法
     * 显示游戏俱乐部。
     */
    onDisable() {
        AL_APP_SDK_MANAGER.emit(AL_GAME_HUA_Define.GameEvent.ON_GAME_CLUB_HIDE, {
            node: this.node,
            hide: false,
        });
    }

    /**
     * 按钮回调处理函数
     * 根据按钮类型执行对应的逻辑。
     * @param {Object} event 按钮点击事件
     * @param {string} type 按钮类型
     */
    handle_button_callback(event, type) {
        switch (type) {
            case "close":
                this.handleCloseButton();
                break;

            case "video":
                this.handleVideoReward();
                break;

            case "coin":
                this.handleCoinPurchase();
                break;
        }
    }

    /**
     * 处理关闭按钮逻辑
     */
    handleCloseButton() {
        this.close();
        if (this.options && this.options.onClose) {
            this.options.onClose();
        }
    }

    /**
     * 处理视频奖励逻辑
     */
    handleVideoReward() {
        AL_GAME_HUA_Common.Common.showVideo({
            success: (videoResult) => {
                // 增加体力
                AL_GAME_HUA_CurrencyData.CurrencyData.getInstance().tianjia_huobi({
                    type: AL_GAME_HUA_CurrencyData.CurrencyType.VIT,
                    num: AL_GAME_HUA_GameConst.GameConst.getInstance().video_vit_count,
                });

                // 上报奖励获取事件
                AL_GAME_HUA_EventConfig.EventConfig.getInstance().assetsReportOutput({
                    source: AL_GAME_HUA_EventConfig.AssetsSource.game,
                    action:
                        videoResult.type === 2
                            ? AL_GAME_HUA_EventConfig.AssetsAction.video_get
                            : AL_GAME_HUA_EventConfig.AssetsAction.share_get,
                    goodsList: [
                        {
                            goods: AL_GAME_HUA_GoodsConfig.GoodsId.vit,
                            num: AL_GAME_HUA_GameConst.GameConst.getInstance().video_vit_count,
                        },
                    ],
                });

                // 购买回调
                if (this.options && this.options.onBuy) {
                    this.options.onBuy();
                }
            },
        });
    }

    /**
     * 处理金币购买逻辑
     */
    handleCoinPurchase() {
        const vitPrice = AL_GAME_HUA_GameConst.GameConst.getInstance().vit_price;

        // 消耗金币
        const currencyResult = AL_GAME_HUA_CurrencyData.CurrencyData.getInstance().shiyong_huobi({
            type: AL_GAME_HUA_CurrencyData.CurrencyType.COIN,
            num: vitPrice,
        }).result;

        if (currencyResult) {
            // 增加体力
            AL_GAME_HUA_CurrencyData.CurrencyData.getInstance().tianjia_huobi({
                type: AL_GAME_HUA_CurrencyData.CurrencyType.VIT,
                num: 1,
            });

            // 上报金币购买事件
            AL_GAME_HUA_EventConfig.EventConfig.getInstance().assetsReportOutput({
                source: AL_GAME_HUA_EventConfig.AssetsSource.game,
                action: AL_GAME_HUA_EventConfig.AssetsAction.coin_get,
                goodsList: [
                    {
                        goods: AL_GAME_HUA_GoodsConfig.GoodsId.vit,
                        num: 1,
                    },
                ],
            });

            // 购买回调
            if (this.options && this.options.onBuy) {
                this.options.onBuy();
            }
        } else {
            // 显示金币不足提示
            AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_tishi_jiedian_mianban({
                str: "金币不足",
            });
        }
    }
}

exports.default = AL_GAME_HUA_Controller;
